From 832f3d7820388da1d73a3f4cc44ff9fbbe9b3bb1 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 29 Apr 2025 18:31:16 -0400 Subject: [PATCH] bin/set-origin: Don't crash if origin has no refspec e.g. if it's using a container instead. Signed-off-by: Colin Walters --- src/ostree/ot-admin-builtin-set-origin.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ostree/ot-admin-builtin-set-origin.c b/src/ostree/ot-admin-builtin-set-origin.c index 1bb0d098..d014fb00 100644 --- a/src/ostree/ot-admin-builtin-set-origin.c +++ b/src/ostree/ot-admin-builtin-set-origin.c @@ -111,12 +111,18 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv g_autofree char *origin_remote = NULL; g_autofree char *origin_ref = NULL; - if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error)) - return FALSE; + if (origin_refspec != NULL) + { + if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error)) + return FALSE; + } + else if (branch == NULL) + return glnx_throw (error, "No host refspec found, branch is required"); + const char *target_branch = branch ?: origin_ref; + g_assert (target_branch); { - g_autofree char *new_refspec - = g_strconcat (remotename, ":", branch ? branch : origin_ref, NULL); + g_autofree char *new_refspec = g_strconcat (remotename, ":", target_branch, NULL); g_autoptr (GKeyFile) new_origin = NULL; new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec); -- 2.30.2